#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include<QTimer>
#include<QSound>  //多媒体模块下的音效和文件

MainScene::MainScene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScene)
{
    ui->setupUi(this);
    //配置主场景

    //设置固定大小
    this->setFixedSize(320,588);

    //设置窗口图标
    this->setWindowIcon(QIcon(":/res/Coin0001.png"));

    //设置标题
    this->setWindowTitle("老刘带你翻金币");

    //退出按钮
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });


    QSound *startSound = new QSound(":/res/TapButtonSound.wav",this);




    MyPushbutton * startBtn=new MyPushbutton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

    chooseScene=new chooselevelScene;
    //监听选择场景的返回按钮
    connect(chooseScene,&chooselevelScene::chooseSceneBack,[=](){
        this->setGeometry(chooseScene->geometry());
        this->show();
    });

    connect(startBtn,&MyPushbutton::clicked,[=](){

        qDebug()<<"btn";
        startSound->play(); //开始音效
        startBtn->zoom1();
        startBtn->zoom2();

        QTimer::singleShot(500,this,[=](){
            chooseScene->setGeometry(this->geometry());
            this->hide();
            chooseScene->show();
        });
    });




}

MainScene::~MainScene()
{
    delete ui;
}


void MainScene::paintEvent(QPaintEvent *){
    QPainter painter(this);

    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    pix.load(":/res/Title.png");
    pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);

    painter.drawPixmap(10,30,pix);
}
